home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / global-one-water.swf / scripts / __Packages / PlayPump.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  5.7 KB  |  207 lines

  1. class PlayPump extends GameObject
  2. {
  3.    var hit;
  4.    var addChildInd;
  5.    var onDragOut;
  6.    var onDragOver;
  7.    var queue;
  8.    var exit;
  9.    var spinnerGuide;
  10.    var leaveLeft;
  11.    var leaveRight;
  12.    var goToSlotGuide;
  13.    var slots;
  14.    var kidsInteractingWithPump;
  15.    var spinner;
  16.    var engine;
  17.    var shadow;
  18.    var _r = 0;
  19.    static var OPTIMUM_SPEED = 16;
  20.    static var OPTIMUM_KIDS = 1;
  21.    static var MAX_KIDS = 5;
  22.    static var SLOT_ANG = 1 / PlayPump.MAX_KIDS;
  23.    static var LITRES_PER_ROTATION = 0.5;
  24.    static var KID_LEAVE_POINT = 0.51;
  25.    static var MIN_TURN_SPEED = 0;
  26.    static var MAX_KIDS_INTERACTING_WITH_PUMP = 7;
  27.    function PlayPump()
  28.    {
  29.       super();
  30.       this.hitArea = this.hit;
  31.       this.hit._visible = false;
  32.       this.addChildInd._visible = false;
  33.       this.onDragOut = this.onRollOut;
  34.       this.onDragOver = this.onRollOver;
  35.    }
  36.    function init(e, q, p)
  37.    {
  38.       super.init(e);
  39.       this.queue = q;
  40.       this.exit = p;
  41.       this.spinnerGuide.init(e);
  42.       this.exit.init(e);
  43.       this.leaveLeft.init(e);
  44.       this.leaveRight.init(e);
  45.       this.goToSlotGuide.init(e);
  46.       this.slots = [];
  47.       this.kidsInteractingWithPump = 0;
  48.       this.swapDepths(this.getTargetDepth());
  49.    }
  50.    function onRollOver()
  51.    {
  52.       this.addChildInd._visible = true;
  53.       this.spinner.filters = [GameObject.GLOW_FILTER];
  54.    }
  55.    function onRollOut()
  56.    {
  57.       this.addChildInd._visible = false;
  58.       this.spinner.filters = [];
  59.    }
  60.    function onRelease()
  61.    {
  62.       if(this.engine.labourPool.length)
  63.       {
  64.          if(this.kidsInteractingWithPump < PlayPump.MAX_KIDS_INTERACTING_WITH_PUMP)
  65.          {
  66.             var _loc2_ = this.engine.labourPool.getKidAtFrontOfQueue();
  67.             _loc2_.sendToNewPath(this.engine.goingToPump,Delegate.create(_loc2_,_loc2_.sendToNewQueue,this.queue));
  68.             this.kidsInteractingWithPump = this.kidsInteractingWithPump + 1;
  69.          }
  70.       }
  71.    }
  72.    function update(f)
  73.    {
  74.       super.update();
  75.       var _loc10_ = this.rotationSpeed;
  76.       var _loc11_ = this._r;
  77.       var _loc5_ = undefined;
  78.       var _loc3_ = undefined;
  79.       this.r = (this._r + this.rotationSpeed) % 1;
  80.       if(this.queue.length)
  81.       {
  82.          if(this.queue[0].distAlongPath == this.queue.path.length)
  83.          {
  84.             var _loc7_ = 100;
  85.             var _loc9_ = -1;
  86.             var _loc4_ = undefined;
  87.             _loc3_ = 0;
  88.             while(_loc3_ < PlayPump.MAX_KIDS)
  89.             {
  90.                if(!this.slots[_loc3_])
  91.                {
  92.                   _loc4_ = this.getPositionOfSlot(_loc3_);
  93.                   _loc4_ = Math.min(_loc4_,1 - _loc4_);
  94.                   if(_loc4_ < _loc7_)
  95.                   {
  96.                      _loc7_ = _loc4_;
  97.                      _loc9_ = _loc3_;
  98.                   }
  99.                }
  100.                _loc3_ = _loc3_ + 1;
  101.             }
  102.             if(_loc9_ >= 0)
  103.             {
  104.                this.slots[_loc9_] = true;
  105.                _loc5_ = this.queue.getKidAtFrontOfQueue();
  106.                _loc5_.joinPump(this,_loc9_);
  107.             }
  108.          }
  109.       }
  110.       var _loc8_ = undefined;
  111.       _loc3_ = 0;
  112.       while(_loc3_ < this.slots.length)
  113.       {
  114.          if((_loc5_ = this.slots[_loc3_]) instanceof Kid)
  115.          {
  116.             _loc8_ = this.getPositionOfSlot(_loc3_);
  117.             f = Math.floor(_loc8_ * this.spinnerGuide.length) + 1;
  118.             if(_loc5_.distAlongPath != f)
  119.             {
  120.                _loc5_.distAlongPath = f;
  121.                _loc5_.mc.setPos(this.spinnerGuide.getPositionAtFrame(f,_loc5_.mc._parent));
  122.             }
  123.          }
  124.          _loc3_ = _loc3_ + 1;
  125.       }
  126.       return _loc10_ * PlayPump.LITRES_PER_ROTATION;
  127.    }
  128.    function getSlotForKid(kid)
  129.    {
  130.       var _loc2_ = 0;
  131.       while(_loc2_ < PlayPump.MAX_KIDS)
  132.       {
  133.          if(this.slots[_loc2_] == kid)
  134.          {
  135.             return _loc2_;
  136.          }
  137.          _loc2_ = _loc2_ + 1;
  138.       }
  139.    }
  140.    function getPositionOfSlot(n)
  141.    {
  142.       return (this._r + (PlayPump.MAX_KIDS - n) * PlayPump.SLOT_ANG) % 1;
  143.    }
  144.    function leave(kid)
  145.    {
  146.       this.kidsInteractingWithPump = this.kidsInteractingWithPump - 1;
  147.       delete this.slots[this.getSlotForKid(kid)];
  148.    }
  149.    function get numberOfKids()
  150.    {
  151.       var _loc3_ = 0;
  152.       var _loc2_ = 0;
  153.       while(_loc2_ < PlayPump.MAX_KIDS)
  154.       {
  155.          if(this.slots[_loc2_] instanceof Kid)
  156.          {
  157.             _loc3_ = _loc3_ + 1;
  158.          }
  159.          _loc2_ = _loc2_ + 1;
  160.       }
  161.       return _loc3_;
  162.    }
  163.    function get rotationSpeed()
  164.    {
  165.       var _loc5_ = undefined;
  166.       var _loc3_ = 0;
  167.       var _loc4_ = 0;
  168.       var _loc2_ = 0;
  169.       while(_loc2_ < this.slots.length)
  170.       {
  171.          if((_loc5_ = this.slots[_loc2_]) instanceof Kid)
  172.          {
  173.             _loc4_ = _loc4_ + 1;
  174.             _loc3_ += _loc5_.pushForce;
  175.          }
  176.          _loc2_ = _loc2_ + 1;
  177.       }
  178.       if(_loc4_ > 0)
  179.       {
  180.          var _loc6_ = _loc3_ / _loc4_;
  181.          _loc2_ = PlayPump.OPTIMUM_KIDS;
  182.          while(_loc2_ < _loc4_)
  183.          {
  184.             _loc3_ -= _loc6_ * (_loc2_ / (PlayPump.MAX_KIDS / PlayPump.OPTIMUM_KIDS));
  185.             _loc2_ = _loc2_ + 1;
  186.          }
  187.          _loc3_ = _loc3_ >= PlayPump.MIN_TURN_SPEED ? _loc3_ : PlayPump.MIN_TURN_SPEED;
  188.       }
  189.       return _loc3_ / 3 * PlayPump.OPTIMUM_SPEED * (1 / (Engine.FPS * 60));
  190.    }
  191.    function get effort()
  192.    {
  193.       return 1;
  194.    }
  195.    function get r()
  196.    {
  197.       return this._r;
  198.    }
  199.    function set r(n)
  200.    {
  201.       var _loc2_ = Math.floor(4 * n * (this.spinner._totalframes - 1) % (this.spinner._totalframes - 1)) + 1;
  202.       this.spinner.gotoAndStop(_loc2_);
  203.       this.shadow.gotoAndStop(_loc2_);
  204.       this._r = n;
  205.    }
  206. }
  207.